﻿// Copyright (c) 2012 Mokah Nnamezie & Andrew Cooper
// Neo4Net graph database - http://neo4net.codeplex.com
//
// This file is part of Neo4Net - a .Net port of the Neo4j graph database
//
// Neo4Net is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

namespace Neo4Net.Kernel
{
    using System;
    using System.Collections.Generic;
    using Neo4Net.GraphDb.Index;
    using Neo4Net.Helpers;
    using Neo4Net.Kernel.Impl.Cache;

    /// <summary>
    /// An implementation of <see cref="IGraphDatabaseService"/> that is used to embed Neo4j
    /// in an application. You typically instantiate it by invoking the
    /// <see cref="EmbeddedGraphDatabase(String)"/> single argument constructor that takes
    /// a path to a directory where Neo4j will store its data files, as such:
    /// <pre>
    /// <code>
    /// IGraphDatabaseService graphDb = new EmbeddedGraphDatabase( &quot;var/graphdb&quot; );
    /// // ... use Neo4Net
    /// graphDb.Shutdown();
    /// </code>
    /// </pre>
    /// For more information, see <see cref="IGraphDatabaseService"/>.
    /// </summary>
    public class EmbeddedGraphDatabase : AbstractGraphDatabase
    {
        /// <summary>
        /// Creates an embedded <see cref="IGraphDatabaseService"/> with a store located in
        /// <c>storeDir</c>, which will be created if it doesn't already exist.
        /// </summary>
        /// <param cref="storeDir">The store directory for the Neo4j store files</param>
        public EmbeddedGraphDatabase(String storeDir)
            : this(storeDir, new Dictionary<string, string>())
        {
        }

        /// <summary>
        /// A non-standard way of creating an embedded <see cref="IGraphDatabaseService"/>
        /// with a set of configuration parameters.
        /// </summary>
        /// <remarks>
        /// Creates an embedded <see cref="IGraphDatabaseService"/> with a store located in
        /// <c>storeDir</c>, which will be created if it doesn't already exist.
        /// </remarks>
        /// <param cref="storeDir">The store directory for the db files</param>
        /// <param cref="params">Configuration parameters</param>
        public EmbeddedGraphDatabase(String storeDir, IDictionary<String, String> parameters)
            : this(storeDir, parameters, Service.Load<IIndexProvider>(), Service.Load<KernelExtension<object>>(),
                    Service.Load<CacheProvider>())
        {
        }

        public EmbeddedGraphDatabase(String storeDir, IDictionary<String, String> parameters, IEnumerable<IIndexProvider> indexProviders,
                IEnumerable<KernelExtension<object>> kernelExtensions, IEnumerable<CacheProvider> cacheProviders)
            : base(storeDir, parameters, indexProviders, kernelExtensions, cacheProviders)
        {
            Run();
        }
    }
}
